<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <script>
    //解构赋值常见用途

    ///////提取json信息////////
    let jsonData = {
        id: 42,
        status: "OK",
        data: [867, 5309]
    };

    let { id, status, data: number } = jsonData;
    console.log(id, status, number);

    ///////函数返回值，信息提取////////
    function example() {
        return {
            foo: 1,
            bar: 2
        };
    }
    let { foo, bar } = example();


    //////// 参数信息提取 ////////
    function f1([x, y, z]) { console.log(x,y,z) }
    f1([1, 2, 3]);

    function f2({x, y, z}) { console.log(x,y,z) }
    f2({z: 3, y: 2, x: 1});

    ////////交换变量 ////////
    let x = 1;
    let y = 2;
    [x, y] = [y, x];
    </script>
</body>

</html>